<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class HomeUser extends Controller{
    public function userRows(){
        $rows=DB::table('index_user')->get();
        $data=[
            "code"=>0,
            "msg"=>'',
            "count"=>count($rows),
            "data"=>$rows
        ];
        return json_encode($data);
    }
    //冻结用户
    public function frz(Request $request){
        $FRZ['state']=$request->post('state');
        $id=$request->post('id');
        $rows=DB::table('index_user')->where('id',$id)->update($FRZ);

    }
    //添加用户
    public function user_insert(Request $request){
        $data=$request->post('result');
        $data['createtime']=date("Y-m-d H:i:s",time());
        $rows=DB::table('index_user')->insert($data);
        if($rows){
            return 1;
        }else{
            return 0;
        }
    }
    //添加消息
    public function message_add(Request $request){
        $data=$request->post('result');
        $data['time']=date('Y-m-d H:i:s',time());
        $rows=DB::table('index_message')->insert($data);
        if($rows){
            return 1;
        }
    }
    //编辑用户
    public function user_edit($id){
        $rows=DB::table('index_user')->where('id',$id)->get()->map(function ($value) {
            return (array)$value;
        })->toArray();
        return view('user.user_edit',['rows'=>$rows[0]]);
    }
    //修改用户
    public function user_update(Request $request){
        $data=$request->post('result');
        $rows=DB::table('index_user')->where('id',$data['id'])->update($data);
        if($rows){
            return 1;
        }
    }
    //删除用户
    public function user_del(Request $request){
        $id=$request->get('id');
        $rows=DB::table('index_user')->where("id",$id)->delete();
        return ;

    }
}